/**
 * 
 */
package dao.hibernate;

import hibernate.Song;
import model.IAlbum;
import model.ISong;

import org.hibernate.criterion.Restrictions;

import dao.ISongDAO;

/**
 * @author ipeel
 *
 */
public class SongDAO extends BaseHibernateDAO implements ISongDAO {
	/* (non-Javadoc)
	 * @see dao.hibernate.ISongDAO#getSongById(java.lang.Integer)
	 */
	public ISong getSongById(Integer songId) {
		return (ISong)sessionFactory.getCurrentSession().load(Song.class, songId);
	}
	
	public ISong getSongByNameInAlbum(String name, IAlbum album) {
		return (ISong)sessionFactory.getCurrentSession()
						.createCriteria(Song.class)
						.add(Restrictions.eq("name", name))
						.add(Restrictions.eq("album.id", album.getId()))
						.uniqueResult();
	}
}
